package com.wjq.boot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * ClassName: com.wjq.boot.config
 * Datetime: 2024/8/3 下午4:21
 * Description:
 *      将前端传来的字符串转化为localDate
 * @author 汪佳泉
 * @version 1.0
 * @since 1.0
 */
@Configuration
public class LocalDateConverter {
    @Bean
    Converter<String, LocalDate> getLocalDateConverter() {
        return new Converter<String, LocalDate>() {
            @Override
            public LocalDate convert(String str) {
                return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            }
        };
    }
}
